package es.masterd.lector_rss.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class FeedsSQLHelper extends SQLiteOpenHelper {
	
	/** 
	 * Sentencia de creación de la base de datos
	 */
	private static final String DB_TABLE_CREATE = 
			"create table if not exists " + FeedsDB.Posts.NOMBRE_TABLA + " (" + 
			FeedsDB.Posts._ID + " integer primary key autoincrement," +
			FeedsDB.Posts.TITLE + " text," +
			FeedsDB.Posts.LINK + " text unique," + 
			FeedsDB.Posts.COMMENTS + " text," +
			FeedsDB.Posts.PUB_DATE + " integer," +
			FeedsDB.Posts.CREATOR + " text," + 
			FeedsDB.Posts.DESCRIPTION + " text" + ")";

	/** 
	 * Constructor
	 * @param context
	 */
	public FeedsSQLHelper(Context context) {
		super(context, FeedsDB.DB_NAME, null, FeedsDB.DB_VERSION);
	}
	
	/** 
	 * Creación de la Base de Datos
	 */
	@Override
	public void onCreate(SQLiteDatabase db) {
		if(db.isReadOnly()) {
			db = getWritableDatabase();
		}
		db.execSQL(DB_TABLE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
		// Por ahora no tenemos que hacer nada
	}

}
